﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _60泛型集合的练习
{
    class Program
    {
        static void Main(string[] args)
        {
            //练习一
            //int[] nums = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            //List<int> listOu = new List<int>();
            //List<int> listJi = new List<int>();
            //for(int i = 0; i < nums.Length; i++)
            //{
            //    if (nums[i] % 2 == 0)
            //    {
            //        listOu.Add(nums[i]);
            //    } 
            //    else
            //    {
            //        listJi.Add(nums[i]);
            //    }
            //}
            //listJi.AddRange(listOu);
            //foreach(int item in listJi)
            //{
            //    Console.Write(item+" ");
            //}
            //Console.ReadKey();


            //练习二
            //Console.WriteLine("请输入一个字符串");
            //string input = Console.ReadLine();
            //char[] chs = new char[input.Length];
            //int i = 0;
            //foreach(var item in input)
            //{
            //    chs[i] = item;
            //    i++;
            //}
            //foreach(var item in chs)
            //{
            //    Console.WriteLine(item);
            //}
            //Console.ReadKey();



            //练习三
            string str = "welcome to china";
            //字符------->出现次数
            //键--------->值
            Dictionary<char, int> dic = new Dictionary<char, int>();
            for (int i = 0;i < str.Length; i++)
            {
                if(str[i] == ' ')
                {
                    continue;
                }
                //如果dic已经包含了当前循环到的这个键
                if (dic.ContainsKey(str[i]))
                {
                    //值再次加一
                    dic[str[i]]++;
                }
                else//这个字符在集合当中是第一次出现
                {
                    dic[str[i]] = 1;
                }
            }
            foreach (KeyValuePair<char,int> kv in dic)
            {
                Console.WriteLine("字母{0}出现了{1}次", kv.Key,kv.Value);
            }
            Console.ReadKey();





        }
    }
}
